<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Document[
  <!ENTITY ppl  "http://example.com/people#">
  <!ENTITY cpt  "http://example.com/concepts#">
  <!ENTITY dc   "http://purl.org/dc/terms/">
  <!ENTITY rif  "http://www.w3.org/2007/rif#">
  <!ENTITY func "http://www.w3.org/2007/rif-builtin-function#">
  <!ENTITY pred "http://www.w3.org/2007/rif-builtin-predicate#">
  <!ENTITY xs   "http://www.w3.org/2001/XMLSchema#">
  <!ENTITY act  "http://www.w3.org/2007/rif-builtin-action#">
]>
<Document
  xmlns="http://www.w3.org/2007/rif#"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <payload>
    <Group>
      <sentence>
        <Group>
          <id>
            <Const type="xs:string">
              calculateFib1</Const>
            </id>
          <sentence>
            <Forall>
              <declare>
                <Var>f</Var>
              </declare>
              <pattern>
                <Member>
                  <instance>
                    <Var>f</Var>
                  </instance>
                  <class>
                    <Const type="&rif;:iri">http://example.com/2009/prd#fib.Fib</Const>
                  </class>
                </Member>
              </pattern>
              <formula>
                <Implies>
                  <if>
                    <Exists>
                      <declare>
                        <Var>n</Var>
                      </declare>
                      <declare>
                        <Var>v</Var>
                      </declare>
                      <formula>
                        <And>
                          <formula>
                            <Frame>
                              <object>
                                <Var>f</Var>
                              </object>
                              <slot ordered="yes">
                                <Const type="&rif;:iri">number</Const>
                                <Var>n</Var>
                                </slot>
                              </Frame>
                          </formula>
                          <formula>
                            <Frame>
                              <object>
                                <Var>f</Var>
                              </object>
                              <slot ordered="yes">
                                <Const type="&rif;:iri">value</Const>
                                <Var>v</Var>
                                </slot>
                              </Frame>
                          </formula>
                          <formula>
                            <External>
                              <content>
                                <Atom>
                                  <op>
                                    <Const type="&rif;:iri">&pred;numeric-equal</Const>
                                  </op>
                                  <args>
                                    <Var>n</Var>
                                    <Const type="xs:integer">
                                      1</Const>
                                    </args>
                                </Atom>
                              </content>
                            </External>
                          </formula>
                          <formula>
                            <External>
                              <content>
                                <Atom>
                                  <op>
                                    <Const type="&rif;:iri">&pred;numeric-equal</Const>
                                  </op>
                                  <args>
                                    <Var>v</Var>
                                    <Const type="xs:integer">
                                      0</Const>
                                    </args>
                                </Atom>
                              </content>
                            </External>
                          </formula>
                        </And>
                      </formula>
                    </Exists>
                  </if>
                  <then>
                    <Do>
                      <actions ordered="yes">
                        <Modify>
                          <target>
                            <Frame>
                              <object>
                                <Var>f</Var>
                              </object>
                              <slot ordered="yes">
                                <Const type="&rif;:iri">value</Const>
                                <Const type="xs:integer">
                                  1</Const>
                                  </slot>
                                </Frame>
                          </target>
                        </Modify>
                        </actions>
                      </Do>
                  </then>
                </Implies>
              </formula>
            </Forall>
          </sentence>
        </Group>
      </sentence>
      <sentence>
        <Group>
          <id>
            <Const type="xs:string">
              calculateFib2</Const>
            </id>
          <sentence>
            <Forall>
              <declare>
                <Var>f</Var>
              </declare>
              <pattern>
                <Member>
                  <instance>
                    <Var>f</Var>
                  </instance>
                  <class>
                    <Const type="&rif;:iri">http://example.com/2009/prd#fib.Fib</Const>
                  </class>
                </Member>
              </pattern>
              <formula>
                <Implies>
                  <if>
                    <And>
                      <formula>
                        <Exists>
                          <declare>
                            <Var>n</Var>
                          </declare>
                          <declare>
                            <Var>v</Var>
                          </declare>
                          <formula>
                            <And>
                              <formula>
                                <Frame>
                                  <object>
                                    <Var>f</Var>
                                  </object>
                                  <slot ordered="yes">
                                    <Const type="&rif;:iri">number</Const>
                                    <Var>n</Var>
                                    </slot>
                                  </Frame>
                              </formula>
                              <formula>
                                <Frame>
                                  <object>
                                    <Var>f</Var>
                                  </object>
                                  <slot ordered="yes">
                                    <Const type="&rif;:iri">value</Const>
                                    <Var>v</Var>
                                    </slot>
                                  </Frame>
                              </formula>
                              <formula>
                                <External>
                                  <content>
                                    <Atom>
                                      <op>
                                        <Const type="&rif;:iri">&pred;numeric-equal</Const>
                                      </op>
                                      <args>
                                        <Var>n</Var>
                                        <Const type="xs:integer">
                                          2</Const>
                                        </args>
                                    </Atom>
                                  </content>
                                </External>
                              </formula>
                              <formula>
                                <External>
                                  <content>
                                    <Atom>
                                      <op>
                                        <Const type="&rif;:iri">&pred;numeric-equal</Const>
                                      </op>
                                      <args>
                                        <Var>v</Var>
                                        <Const type="xs:integer">
                                          0</Const>
                                        </args>
                                    </Atom>
                                  </content>
                                </External>
                              </formula>
                            </And>
                          </formula>
                        </Exists>
                      </formula>
                    </And>
                  </if>
                  <then>
                    <Do>
                      <actions ordered="yes">
                        <Modify>
                          <target>
                            <Frame>
                              <object>
                                <Var>f</Var>
                              </object>
                              <slot ordered="yes">
                                <Const type="&rif;:iri">value</Const>
                                <Const type="xs:integer">
                                  1</Const>
                                  </slot>
                                </Frame>
                          </target>
                        </Modify>
                        </actions>
                      </Do>
                  </then>
                </Implies>
              </formula>
            </Forall>
          </sentence>
        </Group>
      </sentence>
      <sentence>
        <Group>
          <id>
            <Const type="xs:string">
              MakeRecursiveGoal</Const>
            </id>
          <behavior>
            <Priority>10</Priority>
          </behavior>
          <sentence>
            <Forall>
              <declare>
                <Var>f</Var>
              </declare>
              <declare>
                <Var>f1</Var>
              </declare>
              <pattern>
                <Member>
                  <instance>
                    <Var>f</Var>
                  </instance>
                  <class>
                    <Const type="&rif;:iri">http://example.com/2009/prd#fib.Fib</Const>
                  </class>
                </Member>
              </pattern>
              <formula>
                <Implies>
                  <if>
                    <And>
                      <formula>
                        <Exists>
                          <declare>
                            <Var>n</Var>
                          </declare>
                          <declare>
                            <Var>v</Var>
                          </declare>
                          <declare>
                            <Var>n1</Var>
                          </declare>
                          <formula>
                            <And>
                              <formula>
                                <Frame>
                                  <object>
                                    <Var>f</Var>
                                  </object>
                                  <slot ordered="yes">
                                    <Const type="&rif;:iri">number</Const>
                                    <Var>n</Var>
                                    </slot>
                                  </Frame>
                              </formula>
                              <formula>
                                <Frame>
                                  <object>
                                    <Var>f</Var>
                                  </object>
                                  <slot ordered="yes">
                                    <Const type="&rif;:iri">value</Const>
                                    <Var>v</Var>
                                    </slot>
                                  </Frame>
                              </formula>
                              <formula>
                                <External>
                                  <content>
                                    <Atom>
                                      <op>
                                        <Const type="&rif;:iri">&pred;numeric-greater-than</Const>
                                      </op>
                                      <args>
                                        <Var>n</Var>
                                        <Const type="xs:integer">
                                          1</Const>
                                        </args>
                                    </Atom>
                                  </content>
                                </External>
                              </formula>
                              <formula>
                                <External>
                                  <content>
                                    <Atom>
                                      <op>
                                        <Const type="&rif;:iri">&pred;numeric-equal</Const>
                                      </op>
                                      <args>
                                        <Var>v</Var>
                                        <Const type="integer">
                                          0</Const>
                                        </args>
                                    </Atom>
                                  </content>
                                </External>
                              </formula>
                              <formula>
                                <INeg>
                                  <formula>
                                    <Exists>
                                      <declare>
                                        <Var>f1</Var>
                                      </declare>
                                      <formula>
                                        <And>
                                          <formula>
                                            <Member>
                                              <instance>
                                                <Var>f1</Var>
                                              </instance>
                                              <class>
                                                <Const type="&rif;:iri">http://example.com/2009/prd#fib.Fib</Const>
                                              </class>
                                            </Member>
                                          </formula>
                                          <formula>
                                            <Frame>
                                              <object>
                                                <Var>f1</Var>
                                              </object>
                                              <slot ordered="yes">
                                                <Const type="&rif;:iri">number</Const>
                                                <Var>n1</Var>
                                                </slot>
                                              </Frame>
                                          </formula>
                                          <formula>
                                            <External>
                                              <content>
                                                <Atom>
                                                  <op>
                                                    <Const type="&rif;:iri">&pred;numeric-equal</Const>
                                                  </op>
                                                  <args>
                                                    <Var>n1</Var>
                                                    <External>
                                                      <content>
                                                        <Expr>
                                                          <op>
                                                            <Const type="&rif;:iri">&func;numeric-subtract</Const>
                                                          </op>
                                                          <args>
                                                            <Var>n</Var>
                                                            <Const type="xs:integer">
                                                              1</Const>
                                                            </args>
                                                        </Expr>
                                                      </content>
                                                    </External>
                                                  </args>
                                                </Atom>
                                              </content>
                                            </External>
                                          </formula>
                                        </And>
                                      </formula>
                                    </Exists>
                                  </formula>
                                </INeg>
                              </formula>
                            </And>
                          </formula>
                        </Exists>
                      </formula>
                    </And>
                  </if>
                  <then>
                    <Do>
                      <actions ordered="yes">
                        <Assert>
                          <target>
                            <Atom>
                              <op>
                                <Const type="&rif;:iri">http://example.com/2009/prd#fib.Fib</Const>
                              </op>
                              <args>
                                <External>
                                  <content>
                                    <Expr>
                                      <op>
                                        <Const type="&rif;:iri">&func;numeric-subtract</Const>
                                      </op>
                                      <args>
                                        <Var>n</Var>
                                        <Const type="xs:integer">
                                          1</Const>
                                        </args>
                                    </Expr>
                                  </content>
                                </External>
                              </args>
                            </Atom>
                          </target>
                        </Assert>
                        </actions>
                      </Do>
                  </then>
                </Implies>
              </formula>
            </Forall>
          </sentence>
        </Group>
      </sentence>
      <sentence>
        <Group>
          <id>
            <Const type="xs:string">
              computeValue</Const>
            </id>
          <sentence>
            <Forall>
              <declare>
                <Var>f</Var>
              </declare>
              <declare>
                <Var>f1</Var>
              </declare>
              <declare>
                <Var>f2</Var>
              </declare>
              <pattern>
                <Member>
                  <instance>
                    <Var>f</Var>
                  </instance>
                  <class>
                    <Const type="&rif;:iri">http://example.com/2009/prd#fib.Fib</Const>
                  </class>
                </Member>
              </pattern>
              <formula>
                <Implies>
                  <if>
                    <And>
                      <formula>
                        <Exists>
                          <declare>
                            <Var>n</Var>
                          </declare>
                          <declare>
                            <Var>v</Var>
                          </declare>
                          <formula>
                            <And>
                              <formula>
                                <Frame>
                                  <object>
                                    <Var>f</Var>
                                  </object>
                                  <slot ordered="yes">
                                    <Const type="&rif;:iri">number</Const>
                                    <Var>n</Var>
                                    </slot>
                                  </Frame>
                              </formula>
                              <formula>
                                <Frame>
                                  <object>
                                    <Var>f</Var>
                                  </object>
                                  <slot ordered="yes">
                                    <Const type="&rif;:iri">value</Const>
                                    <Var>v</Var>
                                    </slot>
                                  </Frame>
                              </formula>
                              <formula>
                                <External>
                                  <content>
                                    <Atom>
                                      <op>
                                        <Const type="&rif;:iri">&pred;numeric-greater-than</Const>
                                      </op>
                                      <args>
                                        <Var>n</Var>
                                        <Const type="xs:integer">
                                          2</Const>
                                        </args>
                                    </Atom>
                                  </content>
                                </External>
                              </formula>
                              <formula>
                                <External>
                                  <content>
                                    <Atom>
                                      <op>
                                        <Const type="&rif;:iri">&pred;numeric-equal</Const>
                                      </op>
                                      <args>
                                        <Var>v</Var>
                                        <Const type="integer">
                                          0</Const>
                                        </args>
                                    </Atom>
                                  </content>
                                </External>
                              </formula>
                              <formula>
                                <Member>
                                  <instance>
                                    <Var>f1</Var>
                                  </instance>
                                  <class>
                                    <Const type="&rif;:iri">http://example.com/2009/prd#fib.Fib</Const>
                                  </class>
                                </Member>
                              </formula>
                              <formula>
                                <Frame>
                                  <object>
                                    <Var>f1</Var>
                                  </object>
                                  <slot ordered="yes">
                                    <Const type="&rif;:iri">number</Const>
                                    <Var>n1</Var>
                                    </slot>
                                    <slot ordered="yes">
                                      <Const type="&rif;:iri">value</Const>
                                      <Var>v1</Var>
                                      </slot>
                                    </Frame>
                              </formula>
                              <formula>
                                <External>
                                  <content>
                                    <Atom>
                                      <op>
                                        <Const type="&rif;:iri">&pred;numeric-equal</Const>
                                      </op>
                                      <args>
                                        <Var>n1</Var>
                                        <External>
                                          <content>
                                            <Expr>
                                              <op>
                                                <Const type="&rif;:iri">&func;numeric-subtract</Const>
                                              </op>
                                              <args>
                                                <Var>n</Var>
                                                <Const type="xs:integer">
                                                  1</Const>
                                                </args>
                                            </Expr>
                                          </content>
                                        </External>
                                      </args>
                                    </Atom>
                                  </content>
                                </External>
                              </formula>
                              <formula>
                                <External>
                                  <content>
                                    <Atom>
                                      <op>
                                        <Const type="&rif;:iri">&pred;numeric-not-equal</Const>
                                      </op>
                                      <args>
                                        <Var>v1</Var>
                                        <Const type="integer">
                                          0</Const>
                                        </args>
                                    </Atom>
                                  </content>
                                </External>
                              </formula>
                              <formula>
                                <Member>
                                  <instance>
                                    <Var>f2</Var>
                                  </instance>
                                  <class>
                                    <Const type="&rif;:iri">http://example.com/2009/prd#fib.Fib</Const>
                                  </class>
                                </Member>
                              </formula>
                              <formula>
                                <Frame>
                                  <object>
                                    <Var>f2</Var>
                                  </object>
                                  <slot ordered="yes">
                                    <Const type="&rif;:iri">number</Const>
                                    <Var>n2</Var>
                                    </slot>
                                    <slot ordered="yes">
                                      <Const type="&rif;:iri">value</Const>
                                      <Var>v2</Var>
                                      </slot>
                                    </Frame>
                              </formula>
                              <formula>
                                <External>
                                  <content>
                                    <Atom>
                                      <op>
                                        <Const type="&rif;:iri">&pred;numeric-equal</Const>
                                      </op>
                                      <args>
                                        <Var>n2</Var>
                                        <External>
                                          <content>
                                            <Expr>
                                              <op>
                                                <Const type="&rif;:iri">&func;numeric-subtract</Const>
                                              </op>
                                              <args>
                                                <Var>n</Var>
                                                <Const type="xs:integer">
                                                  2</Const>
                                                </args>
                                            </Expr>
                                          </content>
                                        </External>
                                      </args>
                                    </Atom>
                                  </content>
                                </External>
                              </formula>
                              <formula>
                                <External>
                                  <content>
                                    <Atom>
                                      <op>
                                        <Const type="&rif;:iri">&pred;numeric-not-equal</Const>
                                      </op>
                                      <args>
                                        <Var>v2</Var>
                                        <Const type="integer">
                                          0</Const>
                                        </args>
                                    </Atom>
                                  </content>
                                </External>
                              </formula>
                            </And>
                          </formula>
                        </Exists>
                      </formula>
                    </And>
                  </if>
                  <then>
                    <Do>
                      <actions ordered="yes">
                        <Modify>
                          <target>
                            <Frame>
                              <object>
                                <Var>f</Var>
                              </object>
                              <slot ordered="yes">
                                <Const type="&rif;:iri">value</Const>
                                <External>
                                  <content>
                                    <Expr>
                                      <op>
                                        <Const type="&rif;:iri">&func;numeric-add</Const>
                                      </op>
                                      <args>
                                        <Var>v1</Var>
                                        <Var>v2</Var>
                                      </args>
                                    </Expr>
                                  </content>
                                </External>
                                </slot>
                              </Frame>
                          </target>
                        </Modify>
                        </actions>
                      </Do>
                  </then>
                </Implies>
              </formula>
            </Forall>
          </sentence>
        </Group>
      </sentence>
      <sentence>
        <Group>
          <id>
            <Const type="xs:string">
              setResult</Const>
            </id>
          <sentence>
            <Forall>
              <declare>
                <Var>f</Var>
              </declare>
              <pattern>
                <Member>
                  <instance>
                    <Var>f</Var>
                  </instance>
                  <class>
                    <Const type="&rif;:iri">http://example.com/2009/prd#fib.Fib</Const>
                  </class>
                </Member>
              </pattern>
              <formula>
                <Implies>
                  <if>
                    <And>
                      <formula>
                        <Exists>
                          <declare>
                            <Var>n</Var>
                          </declare>
                          <declare>
                            <Var>v</Var>
                          </declare>
                          <formula>
                            <And>
                              <formula>
                                <Frame>
                                  <object>
                                    <Var>f</Var>
                                  </object>
                                  <slot ordered="yes">
                                    <Const type="&rif;:iri">number</Const>
                                    <Var>n</Var>
                                    </slot>
                                  </Frame>
                              </formula>
                              <formula>
                                <Frame>
                                  <object>
                                    <Var>f</Var>
                                  </object>
                                  <slot ordered="yes">
                                    <Const type="&rif;:iri">value</Const>
                                    <Var>v</Var>
                                    </slot>
                                  </Frame>
                              </formula>
                              <formula>
                                <External>
                                  <content>
                                    <Atom>
                                      <op>
                                        <Const type="&rif;:iri">&pred;numeric-not-equal</Const>
                                      </op>
                                      <args>
                                        <Var>v</Var>
                                        <Const type="xs:integer">
                                          0</Const>
                                        </args>
                                    </Atom>
                                  </content>
                                </External>
                              </formula>
                            </And>
                          </formula>
                        </Exists>
                      </formula>
                    </And>
                  </if>
                  <then>
                    <Do>
                      <actions ordered="yes">
                        <Execute>
                          <target>
                            <Atom>
                              <op>
                                <Const type="&rif;:iri">http://www.w3.org/2007/rif-builtin-action#print</Const>
                              </op>
                              <args ordered="yes">
                                <External>
                                  <content>
                                    <Expr>
                                      <op>
                                        <Const type="&rif;:iri">http://www.w3.org/2007/rif-builtin-function#concat</Const>
                                      </op>
                                      <args ordered="yes">
                                        <Const type="xs:string">
                                          Fib(</Const>
                                          <Var>n</Var>
                                          <Const type="xs:string">
                                            )=</Const>
                                            <Var>v</Var>
                                            </args>
                                          </Expr>
                                  </content>
                                </External>
                                </args>
                              </Atom>
                          </target>
                        </Execute>
                        </actions>
                      </Do>
                  </then>
                </Implies>
              </formula>
            </Forall>
          </sentence>
        </Group>
      </sentence>
    </Group>
  </payload>
</Document>



